/// <summary>
/// Copyright 2010 Ivo Limmen (ivo@limmen.org)
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
/// 
/// http://www.apache.org/licenses/LICENSE-2.0
/// 
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// </summary>

using System;
using Services.Logging.Api;
using Services.Configuration.Api;

namespace Services.TaskService.Api
{
    public class BaseTask : ITask
    {
        public BaseTask(string name, string description)
        {
            this.name = name;
            this.description = description;
        }

        private ILogger logger;

        private IResolver localConfiguration;

        private string name;

        private string description;

        #region ITask implementation

        public string GetName()
        {
            return this.name;
        }

        public string GetDescription()
        {
            return this.description;
        }

        public virtual bool RescheduleAfterError()
        {
            return true;
        }

        public virtual void Initialize()
        {
        }

        public virtual void Execute()
        {
        }

        public virtual DateTime? GetNextExecutionTime()
        {
            return null;
        }

        public void SetLogger(ILogger logger)
        {
            this.logger = logger;
        }

        public void SetConfiguration(IResolver resolver)
        {
            this.localConfiguration = resolver;
        }

        #endregion

        protected ILogger GetLogger()
        {
            return this.logger;
        }

        protected string GetSetting(string key)
        {
            return this.localConfiguration.GetSetting(null, GetName(), key);
        }
    }
}
